package com.jnu.myllm.ui.config;

import com.jnu.myllm.ui.intercepter.JwtIntercepter;
import com.jnu.myllm.ui.intercepter.LoginIntercepter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 配置变量：头像上传路径
    @Value("${my.upload.user}")
    private String uploadDir;
    // 添加静态路径资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/user/**")
                .addResourceLocations("file:"+uploadDir+"/");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //没登录的能通过
        registry.addInterceptor(new JwtIntercepter())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/reg2")
                .excludePathPatterns("/images/**")
                .order(100);
        registry.addInterceptor(new LoginIntercepter())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/reg2")
                .excludePathPatterns("/images/**")
                .order(101);
    }
}
